var user_json = null;

function listUser() {

	/*
	 * 
	 */
	var xhr = false;
	xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() {
		var message;
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {

				user_json = JSON.parse(xhr.responseText);

				/*
				 * 
				 * 清空原表数据
				 * 
				 */
				var new_tr_list = document.getElementsByClassName("new_tr");
				var long = new_tr_list.length;

				for (var num = 0; num < long; num++) {
					new_tr_list[0].parentNode.removeChild(new_tr_list[0]);
				}
				/*
				 * 
				 */
				var table_user = document.getElementById("table_user");

				var new_tr;
				var new_td;
				for (var num = 0; num < user_json.length; num++) {
					new_tr = document.createElement("tr");
					table_user.firstElementChild.appendChild(new_tr);
					new_tr.className = "new_tr";
					/*
					 * 
					 */
					new_td = document.createElement("td");
					new_tr.appendChild(new_td);
					new_td.innerHTML = user_json[num].user_account;
					/*
					 * 
					 */
					new_td = document.createElement("td");
					new_tr.appendChild(new_td);
					new_td.innerHTML = user_json[num].user_password;
					/*
					 * 
					 */
					new_td = document.createElement("td");
					new_tr.appendChild(new_td);
					new_td.innerHTML = user_json[num].user_type;
					/*
					 * 
					 */
					new_td = document.createElement("td");
					new_tr.appendChild(new_td);
					if (user_json[num].user_type != "admin") {
						new_td.innerHTML = //
						// '<i title="修改" id="'
						// + user_json[num].user_id
						// + '&'
						// + user_json[num].user_name
						// + '" class="fa fa-pencil"
						// onclick="editUser(this.id)"></i>&nbsp;&nbsp;'+
						'<i title="删除" id="'
								+ user_json[num].user_id
								+ '" class="fa fa-trash" style="color:#ff5063;" onclick="deleteUser(this)"></i>';
					}

				}

				// 让加载图标消失
				document.getElementById("i_pulse").style.display = "none";

			} else {
				// toastr.error(xhr.status);
			}
		}
	}

	xhr.open("POST", "/jxfgyj/user/listUser");

	xhr.send(null);

}
